package com.txw.javaCore.server.service;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

/**
 * @PROJECT_NAME: JavaCoreB2
 * @DESCRIPTION:
 * @Author: 涂玄武
 * @DATE: 2021/1/18 17:32
 */
@Service
public class MailService {

    private static final Logger log = LoggerFactory.getLogger(MailService.class);

    @Autowired
    private JavaMailSender mailSender;

    @Autowired
    private Environment env;

    /**
     * 发送简单的邮件消息
     * @param subject
     * @param content
     * @param tos
     * @return
     * @throws Exception
     */
    public Boolean sendSimpleEmail(final String subject,final String content,final String ... tos) throws Exception{
        SimpleMailMessage message = new SimpleMailMessage();
        message.setSubject(subject);
        message.setText(content);
        message.setTo(tos);
        message.setFrom(env.getProperty("mail.send.from"));
        mailSender.send(message);

        log.info("--发送简单的邮件消息成功--");
        return true;
    }

}
